//
// C++ Implementation: eventhistory
//
// Description: 
//
//
// Author: Christophe Vandeplas <christophe@vandeplas.com>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "eventhistory.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "extramethods.h"

using std::string;
using std::ofstream;
using std::cout;
using std::endl;
using std::vector;

EventHistory::EventHistory()
{
}


EventHistory::~EventHistory()
{
}


/*!
    \fn EventHistory::saveEventHistoryItems(string)
 */
bool EventHistory::saveEventHistoryItems(string filename, vector<EventHistory*> &events)
{
    ofstream myfile (filename.c_str());
    if (myfile.is_open())
    {
        myfile << "<oxsigen type=\"history\">\n";
        for (uint i =0; i < events.size(); i++)
        {
            myfile << "  <thread id=\"" << i << "\">\n";
            for (uint j =0; j < events.at(i)->size() ; j++) {
                myfile << "    <event>" <<xmlConvertChars(events.at(i)->at(j)) << "</event>\n";
            }
            myfile << "  </thread>\n";
        }
        myfile << "</oxsigen>\n";
        myfile.close();
        return true;
    }
    else {
        cout << "Unable to open file" <<endl;
        return false;
    }
}

string EventHistory::xmlConvertChars(string str)
{
    whatToModify('&', "&amp;", str);
    whatToModify('<', "&lt;" , str);
    whatToModify('>', "&gt;" , str);
    return str;
}


/*!
    \fn EventHistory::push_back(string)
 */
void EventHistory::push_back(string event)
{
    _eventItems.push_back(event);
}


string EventHistory::at(int position)
{
    return _eventItems.at(position);
}

uint EventHistory::size()
{
    return _eventItems.size();
}

